package com.hylu.springcloud.controller;

import cn.hutool.core.lang.Console;
import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

@RestController
public class DiseaseController {

    @GetMapping("/getDisease")
    public void getDiseaseList() {
//        Map<String, String> headerMap = new HashMap<>();
//        headerMap.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36");

        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("limit", "30");
        paramMap.put("timeout", "3000");
        paramMap.put("filterTags", "[0,0,0,0,0,0,0]");
        paramMap.put("tagId", "75953");
        paramMap.put("fromLemma", "false");
        paramMap.put("contentLength", "40");
        paramMap.put("page", "1");

        //链式构建请求
        String url = "https://baike.baidu.com/wikitag/api/getlemmas";
//        HttpResponse httpResponse = HttpRequest.post(url)
//                .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36")//头信息，多个头信息多次调用此方法即可
//                .form(paramMap)//表单内容
//                .timeout(20000)//超时，毫秒
//                .contentType("text/html; charset=UTF-8")
//                .execute();


        HttpResponse httpResponse = HttpRequest.post(url)
                .header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36")//头信息，多个头信息多次调用此方法即可
//                .header("Accept","application/json;charset=UTF-8")
//                .contentType("application/json; charset=utf-8")
                .form(paramMap)
                .execute();


        String result2 = new String(httpResponse.body().getBytes(), StandardCharsets.UTF_8);
             Console.log(result2);

    }


}
